<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <p style="color:#fd2f2f;">当前是美国时区:(-7),对应时间：{{ us_time | parseTime('y-m-d h:i:s 星期a') }}</p>
                <el-row>
                    <el-col :md="12" :sm="12">
                        <el-form-item label="订单时间:" prop="order_time.value">
                            <el-date-picker
                                v-model="queryParams.order_time.value"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                            </el-form-item>
                    </el-col>
                    <el-col :md="12" :sm="12">
                            <div>
                                <!-- <el-radio-group @change="day_change" v-model="saleSearch.dateType" size="small" class="mr5">
                                    <el-radio-button :label="0">今天</el-radio-button>
                                    <el-radio-button :label="1">昨天</el-radio-button>
                                    <el-radio-button :label="2">最近7天</el-radio-button>
                                    <el-radio-button :label="3">本月</el-radio-button>
                                </el-radio-group> -->
                                <!-- <el-date-picker v-model="saleSearch.datetime" type="daterange" :picker-options="pickerOptions" range-separator="至" size="small" start-placeholder="开始日期" end-placeholder="结束日期" unlink-panels /> -->
                                <!-- <el-button @click="searchs" type="primary">搜索</el-button> -->
                            </div>
                        </el-col>
                </el-row>
                <el-row>
                        <el-col :md="12" :sm="12">
                            <el-form-item label="编号:" prop="brand.value">
                                <el-input v-model="queryParams.brand.value" placeholder="请输入编号" clearable />
                            </el-form-item>
                        </el-col>
                        <el-col :md="12" :sm="12">
                            <el-form-item class="ele-text-right" label-width="50px">
                                <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                                <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                            </el-form-item>
                        </el-col>
                            
                    </el-row>
            </el-form>

            
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <!-- <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button> -->
                </el-col>
                <el-col :span="1.5">
                    <!-- <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button> -->
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="240" align="left">
                        <template slot-scope="scope">
                            <!-- <el-button class="btn-mar" size="mini" type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button> -->
                            <el-button class="btn-mar" size="mini" type="info" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                            <!-- <el-button class="btn-mar" size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button> -->

                        </template>
                    </el-table-column>
                </template>
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            saleSearch: {
                dateType: 3,
                datetime: '',
            },
            day_changes:0,
            start_time_new: new Date(),
            end_time_new: new Date(),
            us_time: 0,
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'brand',
                },
                // {
                //     visible: true,
                //     label: 'sku',
                //     prop: 'sku',
                // },
                {
                    visible: true,
                    label: '产品图片',
                    prop: 'images',
                    component:'QuickAdminImage',
                },
                {
                    visible: true,
                    label: '最新成本￥',
                    prop: 'material',
                },
                {
                    visible: true,
                    label: '数量',
                    prop: 'count',
                },
                // {
                //     visible: true,
                //     label: '订单时间',
                //     prop: 'order_time',
                // },
            ],
            // 接口地址
            api: {
                index: `/admin/todaycount/index`,
                find: `/admin/todaycount/find`,
                add: `/admin/todaycount/add`,
                edit: `/admin/todaycount/edit`,
                delete: `/admin/todaycount/delete`,
                export: `/admin/todaycount/export`,
                status: `/admin/todaycount/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                brand: { value:undefined, op: '%like%'},
                order_time: { value:[], op: 'range'},

            },

        }
    },
    created () {
        this.now()
        this.initIndex()
    },
    watch: {
        
    },
    methods: {
        // 北京时间
        now() {
            this.us_time = new Date().getTime() - 15 * 3600 * 1000;
            setInterval(() => {
                this.us_time = new Date().getTime() - 15 * 3600 * 1000;
            }, 1000)
        },
        // day_change(val) {
            // this.saleSearch.datetime = '';
        //     let start_time2 = new Date();
        //     if(val == 0){
        //         this.start_time_new.setTime(start_time2.getTime() - 15 * 3600 * 1000);
        //         this.end_time_new.setTime(start_time2.getTime() + 9 * 3600 * 1000);
        //     }else if(val == 1){
        //         this.start_time_new.setTime(start_time2.getTime() - 3600 * 1000 * 24 - 15 * 3600 * 1000);
        //         this.end_time_new.setTime(start_time2.getTime() - 15 * 3600 * 1000);
        //     }else if(val == 2){
        //         this.start_time_new.setTime(start_time2.getTime() - 3600 * 1000 * 24 * 7 - 15 * 3600 * 1000);
        //         this.end_time_new.setTime(start_time2.getTime() - 15 * 3600 * 1000);
        //     }else if(val == 3){
        //         this.start_time_new.setTime(start_time2.getTime() - 15 * 3600 * 1000);
        //         this.end_time_new.setTime(start_time2.getTime() - 15 * 3600 * 1000);
        //     }
        //     this.day_changes = val;
        //     this.handleSkuFind();
        // },
        
        // sku生成回显
        async handleSkuFind() {
            if(this.start_time_new == undefined || this.end_time_new == undefined){
                let start_time2 = new Date()
                start_time2.setTime(start_time2.getTime() - 3600 * 1000 * 24 * 1);
                this.start_time_new = start_time2;
                this.end_time_new = new Date();
            }
            let start_time_new = Date.parse(new Date(this.start_time_new));
            let end_time_new = Date.parse(new Date(this.end_time_new));
            start_time_new = Math.round(start_time_new)/1000;
            end_time_new = Math.round(end_time_new)/1000;
            this.loading = true;
            let response = await this.request.get('/admin/todaycount/index', { 
                day_changes : this.day_changes,
                start_time_new : start_time_new,
                end_time_new : end_time_new
            })
            this.loading = false;
                this.tableData = response.data
                this.total = response.count
                this.start_time = response.start_time
                this.end_time = response.end_time
        },
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        // 编辑
        handleDetail(row) {
            this.handleFind(row)
        },

        // 编辑回显
        async handleFind(row) {
            let response = await this.request.post(this.api.find, { 
                brand: row.brand  ,
                start_time: this.start_time,
                end_time: this.end_time,
            })
            this.findFormData = this.formatFindData(response.data)
            this.editOpen = true
        },
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
